﻿@model EnetaMvc.ApplicationServices.Dto.TagDto[]
           
@{
    var allTags = Html.GetTags();
    var tags = from t in Html.GetTags()
               orderby t.Name
               group t by t.GroupName into Group
               select Group;
    
}
@functions {
    bool IsChecked(TagDto tag)
    {
        return Model.FirstOrDefault(t => t.Id == tag.Id) != null;
    }
}
<table>
    <tr>
    @foreach (var group in tags)
    { 
        <th>@group.Key</th>
    }
    </tr>
    <tr>
    @foreach (var group in tags)
    { 
        <td>
            <table>
            @foreach (var tag in group)
            { 
                var isChecked = IsChecked(tag) ? "checked=\"checked\"" : "";                    
                <tr>
                <td><input type="checkbox" @isChecked value="@tag.Id" name="Tags" /></td>
                <td><label>@tag.Name</label></td>
                </tr>
            }
            </table>
        </td>
    }
    </tr>
</table>